package com.koala.learn.datelearn;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author yantingrui
 * @date 2021/8/18   16:24
 */
public class DateTest {

    private final static String SDF1 = "yyyy-MM-dd HH:mm:ss:SSS";
    private final static String SDF2 = "MM/dd/yyyy HH:mm";
    private final static String SDF3 = "yyyy-MM-dd'T'HH:mm:ss.SSSS";

    public static void main(String[] args) {

        //创建SimpleDateFormat对象实例并定义好转换格式
        SimpleDateFormat sdf = new SimpleDateFormat(SDF3);

        System.out.println("把当前时间转换成字符串：" + sdf.format(new Date()));

        Date date = null;
        try {
            // 注意格式需要与上面一致，不然会出现异常
            date = sdf.parse("2020-08-11T11:05:27.919Z");
        } catch (ParseException e) {
            e.printStackTrace();
        }

        System.out.println("字符串转换成时间:" + date);
    }
}
